

package org.testfire.realm.model.entities;



import static javax.persistence.CascadeType.PERSIST;
import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;

/**
 * This Entity represents the contact information for a User Entity.
 * Since this class is not actually used in the template, commenting will
 * wait until it is.
 *
 * Likely it won't be used, but rather will be replaced by a better thought-out
 * implementation representation of a User->ContactInfo relationship.
 *
 * Remains so as to provide an example of certain annotations.
 *
 */
@Entity
@Table(catalog = "lgsrealm", name = "tbl_contact_info")
public class Contact_info implements Serializable {


	Integer id;
	String first_name;
	String last_name;
	Address primary_address;
	Address mailing_address;
	String phone_primary;
	String phone_alt;
	String phone_fax;
	String email_primary;
	String email_alt;
	String website;
	Date created;
	Date last_updated;


	public Contact_info() {
		this.created = new Date(System.currentTimeMillis());
		this.last_updated = new Date(System.currentTimeMillis());
		this.primary_address = new Address();
		this.mailing_address = new Address();
	}

	/**
	 * Indicates whether some other object is "equal to" this one.
	 *
	 * @param obj the reference object with which to compare.
	 * @return <code>true</code> if this object is the same as the obj argument;
	 *         <code>false</code> otherwise.
	 */
	public boolean equals(Object obj) {
		if (!(obj instanceof Contact_info)) {
			return false;
		}
		return this.id == ((Contact_info) obj).id;
	}


	/**
	 * A simple test which matches the <code>empty</code> operand in the JSP ElExpression
	 * language.
	 * Convenience methods can be added to Entity classes by using the
	 * Transient annotation, which informs the persistence manager that
	 * the method so annotated bears no relation to the underlying persistence
	 * mechanism -- the database, in our case.
	 * @param str The String to be tested.
	 * @return true if the string is not empty.
	 */
	@Transient
	static boolean sTest(String str) {
		return str != null && !str.equals("");
	}

	@Transient
	public boolean isEmpty() {
		if (sTest(first_name) && !sTest(last_name)
				&& !sTest(phone_primary) && !sTest(phone_alt) && !sTest(phone_fax)
				&& !sTest(email_primary) && sTest(email_alt)
				&& sTest(website)) {
			return true;

		}
		return false;
	}


	@Id
	@GeneratedValue(strategy = GenerationType.SEQUENCE)
	public Integer getId() {
		return this.id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getFirst_name() {
		return this.first_name;
	}

	public void setFirst_name(String first_name) {
		this.first_name = first_name;
	}

	public String getLast_name() {
		return this.last_name;
	}

	public void setLast_name(String last_name) {
		this.last_name = last_name;
	}


	@OneToOne(cascade = PERSIST)
	@JoinColumn(name = "primary_address_id")
	public Address getPrimary_address() {
		return this.primary_address;
	}

	public void setPrimary_address(Address primary_address) {
		this.primary_address = primary_address;
	}

	@OneToOne(cascade = PERSIST)
	@JoinColumn(name = "mailing_address_id")
	public Address getMailing_address() {
		return this.mailing_address;
	}

	public void setMailing_address(Address mailing_address) {
		this.mailing_address = mailing_address;
	}

	public String getPhone_primary() {
		return this.phone_primary;
	}

	public void setPhone_primary(String phone_primary) {
		this.phone_primary = phone_primary;
	}

	public String getPhone_alt() {
		return this.phone_alt;
	}

	public void setPhone_alt(String phone_alt) {
		this.phone_alt = phone_alt;
	}

	public String getPhone_fax() {
		return this.phone_fax;
	}

	public void setPhone_fax(String phone_fax) {
		this.phone_fax = phone_fax;
	}

	public String getEmail_primary() {
		return this.email_primary;
	}

	public void setEmail_primary(String email_primary) {
		this.email_primary = email_primary;
	}

	public String getEmail_alt() {
		return this.email_alt;
	}

	public void setEmail_alt(String email_alt) {
		this.email_alt = email_alt;
	}

	public String getWebsite() {
		return this.website;
	}

	public void setWebsite(String website) {
		this.website = website;
	}

	@Temporal(TemporalType.TIMESTAMP)
	public Date getCreated() {
		return this.created;
	}

	public void setCreated(Date created) {
		this.created = created;
	}

	@Temporal(TemporalType.TIMESTAMP)
	public Date getLast_updated() {
		return this.last_updated;
	}

	public void setLast_updated(Date last_updated) {
		this.last_updated = last_updated;
	}


}
